import com.atguigu.bean.Person;
import com.atguigu.config.MainConfig;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Map;

//@Slf4j
public class MainTest {
    public static void main(String[] args) {
//        ClassPathXmlApplicationContext annotationConfigApplicationContext = new ClassPathXmlApplicationContext("beans.xml");
//        Person person = (Person) applicationContext.getBean("person");
//        System.out.println(person);

        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(MainConfig.class);
        Person person = annotationConfigApplicationContext.getBean(Person.class);
        System.out.println(person);

        //查看bean中id的定义方法
        String[] beanNamesForType = annotationConfigApplicationContext.getBeanNamesForType(Person.class);
        for (String s : beanNamesForType) {
            System.out.println(s);
        }

        /**
         * 可以用来来看指定注解加载的类
         */
        String[] beans = annotationConfigApplicationContext.getBeanNamesForAnnotation(Configuration.class);
        for (String bean : beans) {
            System.out.println(bean);
        }
        System.out.println("-----获取注解中所有的class");
        Map<String, Object> beans2 = annotationConfigApplicationContext.getBeansWithAnnotation(Configuration.class);
        for (Map.Entry<String, Object> itemEntity : beans2.entrySet()) {
            String key = itemEntity.getKey();
            Object value = itemEntity.getValue();
            System.out.println("beanId="+key);
//            System.out.println(value.getClass());
        }
    }
}
